﻿using System;
using System.Collections.Generic;

namespace CacheSharp.Core
{
    /// <summary>
    /// 读取接口
    /// </summary>
    internal interface IReader
    {
        /// <summary>
        /// 判断键值是否存在
        /// </summary>
        /// <param name="groupName">群组名</param>
        /// <param name="key">键值</param>
        /// <returns>键值是否存在</returns>
        bool Exist(string groupName, string key);

        /// <summary>
        /// 得到键值的过期时间
        /// </summary>
        /// <param name="groupName">群组名</param>
        /// <param name="key">键值</param>
        /// <returns>键值的过期时间。键值不存在时返回null</returns>
        DateTime? GetExpireTime(string groupName, string key);

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="groupName">群组名</param>
        /// <param name="key">键值</param>
        /// <returns>数据值。键值不存在时返回null</returns>
        object GetValue(string groupName, string key);

        /// <summary>
        /// 获取字符串数据
        /// </summary>
        /// <param name="groupName">群组名</param>
        /// <param name="key">键值</param>
        /// <returns>字符串值。键值不存在时返回null</returns>
        string GetString(string groupName, string key);

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="groupName">群组名</param>
        /// <param name="key">键值</param>
        /// <returns>数据值。键值不存在时返回默认值</returns>
        T GetValue<T>(string groupName, string key);
        Dictionary<string, object> GetValues(string groupName, string keyPart);

        /// <summary>
        /// 弹出数据
        /// </summary>
        /// <param name="groupName">群组名</param>
        /// <param name="key">键值</param>
        /// <returns>数据值。键值不存在时返回null</returns>
        object PopValue(string groupName, string key);

        /// <summary>
        /// 弹出字符串
        /// </summary>
        /// <param name="groupName">群组名</param>
        /// <param name="key">键值</param>
        /// <returns>字符串值。键值不存在时返回null</returns>
        string PopString(string groupName, string key);

        /// <summary>
        /// 弹出数据
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="groupName">群组名</param>
        /// <param name="key">键值</param>
        /// <returns>数据值。键值不存在时返回默认值</returns>
        T PopValue<T>(string groupName, string key);
    }
}
